#!/usr/bin/python
# -*- coding: UTF-8 -*-

import Tkinter
from Tkinter import *
import tkFont as tkFont
import time
import pyHook
root = Tkinter.Tk()
root.title('维修锁屏')
#——窗口配置
root.wm_attributes('-topmost',1)
w = root.winfo_screenwidth()
h = root.winfo_screenheight()
root.geometry("600x100+%d+%d" %(w/2-330,h/2-70))
root.resizable(width=False, height=False)
#——锁屏前界面
labelenter1=Label(root, text='设置锁屏密码', font=('Arial', 14))
texte1 = StringVar()
e1 = Tkinter.Entry(root, textvariable=texte1,font=('Arial', 14))
#——锁屏中界面
ft1=tkFont.Font(family='Fixdsys', size=h/7, weight=tkFont.BOLD)
label0=Label(root, text='',height = 10)
label1=Label(root, text='维修中', font=ft1,)
label2=Label(root, text='请勿操作!', font=ft1)
label3=Label(root, text='输密码解锁',height = 2)
label4=Label(root, text='密码错误',height = 1)
ft2=tkFont.Font(family='Fixdsys', size=h/30, weight=tkFont.BOLD)
var1=var2=''
flag=1#锁屏前=1，锁屏后=2
#——退出锁屏
def quitroot():
    global var2
    var2 = e1.get()
    print ('var1:'+var1)
    print ('var2:'+var2)
    if var2==var1 :
        root.destroy()
    else:
        label4.pack()
bt1=Button(root,text='点击退出锁屏', font=ft2,command = quitroot)
#——进入锁屏
def enterroot():
    global flag
    flag=2
    print('开始锁屏')
    global var1
    var1=e1.get()
    print('开密码:' + var1)
    root.geometry("%dx%d+0+0" %(w,h))
    label0.pack()
    label1.pack()
    label2.pack()
    label3.pack()
    texte1.set('')
    e1.pack_forget()
    e1.pack()
    e1.focus()
    bt1.pack()
    root.overrideredirect(True)
    bt2.pack_forget()
    labelenter1.pack_forget()
    localtime = time.localtime(time.time())
    #print time.strftime("%H:%M:%S", time.localtime()))
    global timesum
    timesum=time.time()
    label5time=Label(root, text='开始维修时间：'+time.strftime("%H:%M:%S", time.localtime()),height = 1).pack()
#——回车事件
def enterpress(event):
    if flag==1:
        enterroot()
    else:
        quitroot()
#——强退事件
def protect():
    if flag==2:
        print('防强退')
    else:
        root.destroy()
root.bind('<Return>',enterpress)
bt2 = Button(root,text='确认锁屏',command= enterroot)
labelenter1.pack()
e1.pack()
e1.focus()
bt2.pack()
root.protocol("WM_DELETE_WINDOW", protect)
root.mainloop()
